package com.applink.sell_proof.dialog;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.KeyEvent;

public class MyProgressDialog extends DialogFragment {

	private static MyProgressDialog uniqueInstance;

	public static MyProgressDialog getInstance() {
		if (uniqueInstance == null) {
			synchronized (MyProgressDialog.class) {
				if (uniqueInstance == null) {
					uniqueInstance = new MyProgressDialog();
				}
			}
		}
		return uniqueInstance;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {

		final ProgressDialog dialog = new ProgressDialog(getActivity());
		dialog.setMessage("loading");
		dialog.setIndeterminate(true);
		dialog.setCancelable(false);
		dialog.setCanceledOnTouchOutside(false);

		// Disable the back button
		OnKeyListener keyListener = new OnKeyListener() {

			@Override
			public boolean onKey(DialogInterface dialog, int keyCode,
					KeyEvent event) {

				return keyCode == KeyEvent.KEYCODE_BACK;
			}
		};
		dialog.setOnKeyListener(keyListener);
		return dialog;
	}

}